# coding:utf-8
import urllib.request
import ssl

context = ssl._create_unverified_context()  # 忽略安全
url = "https://www.baidu.com/s"
word = {"wd": "尹成"}
word = urllib.parse.urlencode(word)  # 编码成字符串
newurl = url+"?"+word  # 拼接网址
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"
}

print(newurl)

request = urllib.request.Request(newurl, headers=headers)
response = urllib.request.urlopen(request, context=context)

data = response.read().decode('utf8')

# print(data)

with open('baidu.html', 'w', encoding='utf-8') as f:
    f.write(data)
